/**
 * @file main.cpp
 * @author your name (you@domain.com)
 * @brief 
 * @version 0.1
 * @date 2022-10-20
 * 
 * @copyright Copyright (c) 2022
 * 
 */
#include <QGuiApplication>
#include <QQmlApplicationEngine>

#include "camera/videocapturer.h"
#include "./commonapi.h"
#include "./pointertypes.h"
#include "./screenrecoder.h"
#include "./videosurface.h"
#include "videosurface/basesurface.h"

int main(int argc, char *argv[]) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
  QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
  QGuiApplication app(argc, argv);

  register2meta();

  // 注册自定义类型
  qmlRegisterType<VideoSurface>("VideoSurface", 1, 0, "VideoSurface");
  qmlRegisterType<VideoCapturer>("VideoCapturer", 1, 0, "VideoCapturer");
  qmlRegisterType<BaseSurface>("VideoCapturer", 1, 0, "BaseSurface");
  qmlRegisterType<ScreenRecoder>("ScreenRecoder", 1, 0, "ScreenRecoder");

  qmlRegisterSingletonType<CommonAPI>(
      "CommonAPI", 1, 0, "CommonAPI",
      [](QQmlEngine *, QJSEngine *scriptEngine) -> QObject * {
        return new CommonAPI();
      });

  QQmlApplicationEngine engine;
  const QUrl url(QStringLiteral("qrc:/qml/main.qml"));
  QObject::connect(
      &engine, &QQmlApplicationEngine::objectCreated, &app,
      [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl) QCoreApplication::exit(-1);
      },
      Qt::QueuedConnection);
  engine.load(url);

  return app.exec();
}
